package com.lk2.core.remoting.remotingAdapters
{
	import com.lk2.core.config.IConfig;
	
    

    /**
     * Used to store Application config settings, and the
     * FlashRemoting channel and endpoint url settings, with this you
     * won't need define a -services compiler argument for the project.
     *
     * @author: Luca Bianchi
     **/
    [Bindable(event="configChange")]
	public class ColdFusionAdapter implements IRemoteObjectAdapter
	{
		private var _configObj:IConfig;
		private var _timezoneOffset:Number //est=4 or 5, depending on DST
		private var _use_stub_data:Boolean;

        private  const default_context_root:String = "/"; // adjust as needed for your default server.

		
		public function ColdFusionAdapter(configObj:IConfig, useStubData:Boolean=false){
			_configObj = configObj;
			_use_stub_data = useStubData;
		}
		
        public function get TIMEZONEOFFSET():Number{
        	return this._timezoneOffset;
        } 
        
        // debug setting to switch between live and stub data
        public function get USE_STUB_DATA():Boolean{
        	return this._use_stub_data;
        }

        // Flash remoting config issues
        public function get CHANNELID():String
        {
        	return _configObj.getString('amf_channel_id');
        } 


        /**
         * pull the context-root out of the flash var, if it's defined in your <object/> or <embed/> tags.
         * ex: contextRoot=/flex
         **/        
        private function get CONTEXT_ROOT():String
        {
            if( _configObj.getString('context_root') != null )
            {
                return _configObj.getString('context_root');
            }
            return this.default_context_root;
        }
        
        
        // return the correct endpoint, if this is server from an HTTP request
        // return the default localhost:8500 for development, if FlexBuilder launches
        // the application locally with an absolute path (file://c:\...)
        public function get AMFENDPOINT():String
        {
                return this.CONTEXT_ROOT +"/flex2gateway";
        }

        
        public function get DESTINATION():String
        {
                return "ColdFusion";
        }


    }
}
